<!-- 今日小结 -->
<template>
  <div class="pk_page" v-if="isEdit || list.length">
    <div class="main_label">
      <span>PK数据</span>
      <span v-show="isEdit && list.length" @click="deleteData" class="delete_btn">删除</span>
    </div>
    <Row class="label_warp" v-show="isEdit && !list.length">
      <Col span="24" class="tips">
        <Icon type="md-alert" class="tips_icon" />
        <div>
          您可右侧“添加联代”或“添加竞品”按钮，向日报中添加竞品或联代方的来人及成交信息，系统将自动生成PK对比数据
        </div>
      </Col>
    </Row>
    <div v-show="list.length" class="pk_content">
      <div class="title">
        <div class="item_txt">
          <span v-if="pkDataFlagObj.clueStatus == 1">线索</span>
          <span v-if="pkDataFlagObj.arrivePeopleStatus == 1">来人</span>
          <span v-if="pkDataFlagObj.clinchDealStatus == 1">成交</span>
        </div>
      </div>
      <div v-for="(item, index) in list" :key="index" class="item">
        <div class="item_label">
          <Tooltip :content="item.generationName" placement="top" v-if="item.generationName.length > 18">
            {{ item.generationName }}
          </Tooltip>
          <div v-else>
            {{ item.generationName }}
          </div>
          <span :class="['tag', item.projectType == 1 ? 'blue' : item.projectType == 2 ? 'green' : 'yeloow']">
            {{ item.projectType == 1 ? '联' : item.projectType == 2 ? '竟' : '我' }}
          </span>
          <span class="tag golden" v-if="item.projectType == 1 && item.cooperationModeType">
            {{ item.cooperationModeType == 1 ? '甲' : '乙' }}
          </span>
        </div>

        <div class="item_num">
          <!-- <span>{{ item.clueCount }}</span>
          <span>{{ item.visitorCount }}</span>
          <span>{{ item.orderCount }}</span> -->
          <span v-if="pkDataFlagObj.clueStatus == 1 && item.projectType == 0">
            {{ item.clueCount }}
          </span>
          <span v-if="pkDataFlagObj.arrivePeopleStatus == 1 && item.projectType == 0">
            {{ item.visitorCount }}
          </span>
          <span v-if="pkDataFlagObj.clinchDealStatus == 1 && item.projectType == 0">
            {{ item.orderCount }}
          </span>

          <span v-if="pkDataFlagObj.clueStatus == 1 && item.projectType == 2">
            {{ pkDataFlagObj.competitorsClueStatus == 1 ? item.clueCount : '-' }}
          </span>
          <span v-if="pkDataFlagObj.arrivePeopleStatus == 1 && item.projectType == 2">
            {{ pkDataFlagObj.competitorsArrivePeopleStatus == 1 ? item.visitorCount : '-' }}
          </span>
          <span v-if="pkDataFlagObj.clinchDealStatus == 1 && item.projectType == 2">
            {{ pkDataFlagObj.competitorsClinchDealStatus == 1 ? item.orderCount : '-' }}
          </span>

          <span v-if="pkDataFlagObj.clueStatus == 1 && item.projectType == 1">
            {{ pkDataFlagObj.syndicationClueStatus == 1 ? item.clueCount : '-' }}
          </span>
          <span v-if="pkDataFlagObj.arrivePeopleStatus == 1 && item.projectType == 1">
            {{ pkDataFlagObj.syndicationArrivePeopleStatus == 1 ? item.visitorCount : '-' }}
          </span>
          <span v-if="pkDataFlagObj.clinchDealStatus == 1 && item.projectType == 1">
            {{ pkDataFlagObj.syndicationClinchDealStatus == 1 ? item.orderCount : '-' }}
          </span>
        </div>
      </div>
      <div class="show_more" v-if="allList.length > 5" @click="showMore">
        {{ showMoreFlag ? '收起全部' : '展开全部' }}
      </div>
    </div>
    <!-- <div v-show="list.length" class="pk_content">
      <div class="title">
        <div class="item_txt">
          <span>线索</span>
          <span>来人</span>
          <span>成交</span>
        </div>
      </div>
      <div v-for="(item, index) in list" :key="index" class="item">
        <div class="item_label">
          <span :class="['tag', item.projectType == 1 ? 'blue' : item.projectType == 2 ? 'green' : 'yeloow']">
            {{ item.projectType == 1 ? '联' : item.projectType == 2 ? '竟' : '我' }}
          </span>
          <Tooltip :content="item.generationName" placement="top" v-if="item.generationName.length > 18">
            {{ item.generationName }}
          </Tooltip>
          <div v-else>
            {{ item.generationName }}
          </div>
        </div>

        <div class="item_num">
          <span>{{ item.clueCount }}</span>
          <span>{{ item.visitorCount }}</span>
          <span>{{ item.orderCount }}</span>
        </div>
      </div>
      <div class="show_more" v-if="allList.length > 5" @click="showMore">
        {{ showMoreFlag ? '收起全部' : '展开全部' }}
      </div>
    </div> -->
  </div>
</template>

<script>
  import dailyApi from '@/biz/buildingHome/daily'

  export default {
    props: ['isEdit'],
    data() {
      return {
        list: [],
        showMoreFlag: false,
        allList: [],
        pkDataFlagObj: null
      }
    },
    methods: {
      show(data) {
        this.list = data
        this.getData()
      },
      deleteData() {
        this.$Modal.confirm({
          title: '“PK数据”删除确认',
          content: `请确认，是否将“PK数据”从案场日报中删除？<span style='color:red'>删除后将无法恢复</span>`,
          okText: '确认删除',
          closable: true,
          onOk: () => {
            let params = {
              buildingId: this.$dt.buildInfo().housesId,
              date: this.$parent.currentDate
            }
            dailyApi.deleteDailyGeneration(params).then((res) => {
              this.$Message.success('删除成功')
              this.getData()
            })
          }
        })
      },
      showMore(flag = true) {
        this.showMoreFlag = flag ? !this.showMoreFlag : flag
        if (this.showMoreFlag) {
          this.list = this.allList
        } else {
          this.list = this.allList.slice(0, 5)
        }
        console.log(this.list)
      },
      findDailyGenerationAllocationHomePage() {
        let params = {
          buildingId: this.$dt.buildInfo().housesId
        }
        dailyApi.findDailyGenerationAllocationHomePage(params).then((res) => {
          console.log(res, 'pk')
          this.pkDataFlagObj = res
        })
      },
      getData() {
        this.findDailyGenerationAllocationHomePage()
        let params = {
          buildingId: this.$dt.buildInfo().housesId,
          startTime: this.$parent.currentDate,
          endTime: this.$parent.currentDate
        }
        this.$emit('callBack', this.allList.length > 0 ? true : false)
        dailyApi.pkDataList(params).then((res) => {
          if (res) {
            this.allList = res
            if (res.length > 5) {
              this.list = res.slice(0, 5)
            } else {
              this.list = res.slice(0, res.length)
            }
          }
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .pk_page {
    width: 100%;
    margin-bottom: 15px;

    .main_label {
      display: flex;
      justify-content: space-between;
      line-height: 20px;
      border-left: 5px solid #2b85e4;
      padding-left: 8px;
      font-size: 15px;
      margin-bottom: 15px;

      .delete_btn {
        color: #2d8cf0;
        cursor: pointer;
        margin-right: 10px;
        font-size: 13px;
      }
    }

    .label_warp {
      margin-bottom: 15px;
      background-color: rgba(254, 252, 236, 1);
      width: auto;
      line-height: 32px;
      padding: 10px;
      border-radius: 5px;

      .tips {
        line-height: 20px;
        font-size: 14px;
        display: flex;

        .tips_icon {
          font-size: 20px;
          color: #0f42a7;
          vertical-align: sub;
        }
      }
    }

    .pk_content {
      border: 1px solid #ccc;
      padding: 15px;
      border-radius: 5px;

      .title {
        display: flex;
        justify-content: flex-end;
        padding-bottom: 10px;
        font-size: 14px;
        border-bottom: 1px solid #ccc;

        .item_txt {
          width: 40%;

          span {
            display: inline-block;
            width: 33%;
            text-align: center;
          }
        }
      }

      .item {
        display: flex;
        justify-content: space-between;
        padding-top: 10px;
        font-size: 14px;

        .item_label {
          flex: 1;
          display: flex;
          width: 60%;

          .tag {
            border-radius: 3px;
            padding: 1px 8px;
            font-size: 12px;
            line-height: 18px;
            margin: 0 5px;
          }

          ::v-deep .ivu-tooltip-rel {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            width: 85%;
          }

          .blue {
            background-color: rgba(25, 109, 255, 0.1);
            color: #196dff;
          }

          .green {
            background-color: rgba(38, 192, 204, 0.1);
            color: #26c0cc;
          }

          .yeloow {
            background-color: rgba(253, 110, 25, 0.1);
            color: #fd6e19;
          }
          .golden {
            background-color: rgba(189, 157, 112, 0.1);
            color: #bd9d70;
            margin: 0;
          }
        }

        .item_num {
          width: 40%;

          span {
            display: inline-block;
            width: 33%;
            text-align: center;
          }
        }
      }

      .show_more {
        text-align: center;
        color: #0f42a7;
        line-height: 20px;
        cursor: pointer;
        margin-top: 10px;
      }
    }
  }
</style>
